package com.ats.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ats.model.User;
import com.ats.service.AddMsgService_cl;
import com.ats.service.StudentService_xh;
import com.ats.service.TeacherService_xh;
import com.ats.serviceimpl.AddMsgServiceImpl_cl;
import com.ats.serviceimpl.StudentServiceImpl_xh;
import com.ats.serviceimpl.TeacherServiceImpl_xh;



public class AddMsgController_cl extends HttpServlet{
	AddMsgService_cl am = new AddMsgServiceImpl_cl();
	StudentService_xh stus =new StudentServiceImpl_xh();
	TeacherService_xh tea = new TeacherServiceImpl_xh();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session =req.getSession();		
		String ntext = req.getParameter("Msg");
		String ndata = req.getParameter("Date");
		int tid =tea.FindTeacherTid();
		int sid =stus.FindStudentSid();
		int iid =((User)session.getAttribute("user")).getIid();
		System.out.println(tid);
		System.out.println(iid);
		System.out.println(sid);
		boolean flag = am.AddMsgByNid(ntext, ndata, iid, sid, tid);
		PrintWriter pw = resp.getWriter();
		pw.write(flag+"");
	}
}
